import Vue from 'vue'
import Vuex from 'vuex'
// import { setToken } from '@/utils/token'
import { getAdminInfoByPhone } from '@/api/Admin/admin'
import {findStudentBy} from '@/api/Student/index'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    name:'',
    profession:'',
    id:'',
    adminInfo:{},
    stuInfo:{},
    userInfo:{}
  },
  getters: {
    // name: state => state.adminName || [], // 名称
    // adminNum:state => state.adminNum || [], // 工号
    // adminPhone:state => state.adminPhone || [], // 手机号
    // adminProfession:state => state.adminProfession || [], // 职业
    // adminSex: state => state.adminSex || [], // 用户性别
    // adminId: state => state.adminId || [],//ID
    // stuName:state => state.stuName || [],//stuname
    // stuId:state => state.stuId || [],//ID
  },
  mutations: {
    USERLOGIN () {

    },
    UPDATETOKEN () {

    },
    UPDATEUSERINFO (state, userInfo) {
      state.id=''
      state.name=''
      state.profession=''
      state.id = userInfo.adminId
      state.name=userInfo.adminName
      state.profession=userInfo.adminProfession
      state.adminInfo=userInfo
      console.log('111222222222',state)
    },
    UPDATEStuINFO(state,stuInfo){
      state.id=''
      state.name=''
      state.profession=''
      state.id = stuInfo.stuId
      state.name=stuInfo.stuName
      state.profession='用户'
      state.stuInfo=stuInfo
      console.log('111userInfo',state)
    },
    UPDATEALLINFO(state){
      state.name=''
      state.profession='',
      state.id='',
      state.adminInfo='',
      state.stuInfo=''
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setStuHead(state, stuHead) {
      state.userInfo.stuHead = stuHead
    },
  },
  actions: {
    //管理员
    async  initUserInfo ({ commit },admin_phone) {
      console.log('dianhua',admin_phone)
      const result = await getAdminInfoByPhone(admin_phone)
      if (result.data.code === 0) {
        commit('UPDATEUSERINFO', result.data.data[0])
        // console.log('详情', result.data.data[0])
      }
    },
    //学生
    async  initStuInfo ({ commit },stu_phone) {
      console.log('dianhua',stu_phone)
      const result = await findStudentBy(stu_phone)
      if (result.data.code === 0) {
        commit('UPDATEStuINFO', result.data.data[0])
        console.log('stu详情', result.data.data[0])

      }
    },
  },
  modules: {
  },
  plugins: [createPersistedState()]
})
